#include "media/logic/MediaLogicBT.h"
#include <exdisp.h>
#include <shldisp.h>
#include <shlguid.h>

MediaLogicBT::MediaLogicBT(QMap<QString, QMap<QString, QString>>  &RGLRLSMAP,
                             QSqlDatabase *DB,
                             QMap<QString, QString> &QSSMAP)
    :MediaLogicCT(RGLRLSMAP, DB, QSSMAP){

    diary("init successful", Diary::Debug)
}


void MediaLogicBT::mdplr_plmd_change(){
    QStringList playmodeList = MT_playMdStyle.values();
    QString value = playmodeList[impact_int["mdrs-mode-pixmap"]];
    MT_mdplermode->doconfigur_pixmap(value);
    if (impact_int["mdrs-mode-pixmap"] +1 >= MT_playMdStyle.size())
    {
        impact_int["mdrs-mode-pixmap"] = 0;
    }
    else
    {
        impact_int["mdrs-mode-pixmap"]++;
    }
    mediaModeType = MT_playMdStyle.key(value);
    RT_sliderShow->backview();
}


void MediaLogicBT::mdplr_volumesld_change(int volume){
    MT_audioPut->setVolume(volume);
    if (volume > impact_int["md-hstr-volume"])
    {
        MT_volumeView->doconfigur_pixmap(MT_volumeStyle[MEDIAVOLUME::VOLUME_UP]);

    } else{
        MT_volumeView->doconfigur_pixmap(MT_volumeStyle[MEDIAVOLUME::VOLUME_DOWM]);
    }
    impact_int["md-hstr-volume"] = volume;
    MULTI_VOLUME_QTIER.start();
}


void MediaLogicBT::mdplr_volumevdo_change(bool volume){
    int volumenum = MT_audioPut->volume();
    if (volumenum > impact_int["md-hstr-volume"])
    {
        MT_volumeView->doconfigur_pixmap(MT_volumeStyle[MEDIAVOLUME::VOLUME_UP]);

    } else{
        MT_volumeView->doconfigur_pixmap(MT_volumeStyle[MEDIAVOLUME::VOLUME_DOWM]);
    }
    if (volume)
    {
        volumenum++;
    }
    else
    {
        volumenum--;
    }
    impact_int["md-hstr-volume"] = volume;
    MT_audioPut->setVolume(volumenum);
    MULTI_VOLUME_QTIER.start();
}


void MediaLogicBT::mdplr_ratio_change(double ratio){
    QString strchar = MT_speedView->text();
    MT_speedView->doconfigur_text(strchar.replace(strchar.mid(1,-1), QString::number(ratio)));
    MT_MediaPlayer->setPlaybackRate(ratio);
}


void MediaLogicBT::mdplr_volume_icochange(){
    if (impact_int["md-hstr-volume"] && impact_int["md-hstr-volume"] >= 50){
        MT_volumeView->doconfigur_pixmap(MT_volumeStyle[MEDIAVOLUME::VOLUME_NOTICE]);
    } else if (impact_int["md-hstr-volume"] && impact_int["md-hstr-volume"] < 50)
    {
        MT_volumeView->doconfigur_pixmap(MT_volumeStyle[MEDIAVOLUME::VOLUME_SMALL]);

    } else {
        MT_volumeView->doconfigur_pixmap(MT_volumeStyle[MEDIAVOLUME::VOLUME_MUTE]);
    }
}


void MediaLogicBT::mdplr_plpro_change(qint64 pro){
    //播放文件的总时长
    qint64 total_duration = MT_MediaPlayer->duration();
    if (total_duration && MT_tracksSlider->maximum() != total_duration)
    {
        int step = total_duration / (100 * 1000);
        MT_tracksSlider->setMaximum(total_duration);
        RT_videoWidget->mtpl_durslider->setMaximum(total_duration);
        MT_tracksSlider->setSingleStep(step);
    }
    //当前正在播放的时长，转格式
    QString ProgressTime = definfc.g_plyduration(pro);
    QString TotalProgressTime = definfc.g_plyduration(total_duration);
    //如果没有弹出了视频窗口，操作主窗口的进度值即可
    //设置播放开始，结束的时长字符
    MT_duration->doconfigur_text(ProgressTime);
    RT_videoWidget->mtpl_begindra->doconfigur_text(ProgressTime);
    RT_videoWidget->mtpl_finishdra->doconfigur_text(TotalProgressTime);
    //设置进度条最大值
    MT_tracksSlider->setValue(pro);
    RT_videoWidget->mtpl_durslider->setValue(pro);
    RT_lyricLabel->setText(ProgressTime);
}


void MediaLogicBT::mdplr_popuplate_fadjusted(int type){
    NAdjustedWin *MT_adjustedMdl = new NAdjustedWin(nullptr, true);
    MT_adjustedMdl->setFixedSize(120,60);
    if (type)
    {
        MT_adjustedMdl->setValue(MT_MediaPlayer->playbackRate());
        MT_adjustedMdl->sico(":/PIXMAP/bench/adjusted-retio.png");
        MT_adjustedMdl->setPrograssAttribute(0, 4, 0.1);
        connect(MT_adjustedMdl, &NAdjustedWin::positionChange, this, &MediaLogicBT::mdplr_ratio_change);
    }
    else
    {
        MT_adjustedMdl->setValue(MT_audioPut->volume());
        MT_adjustedMdl->sico(":/PIXMAP/bench/adjusted-volume.png");
        connect(MT_adjustedMdl, &NAdjustedWin::positionChange, this, &MediaLogicBT::mdplr_volumesld_change);
    }
    abstract_reserve_loader();
    QPoint btpos = mapToGlobal(BT_mainWidget->pos());
    MT_adjustedMdl->setVisible(true);
    int x = btpos.x() + BT_mainWidget->width() - MT_adjustedMdl->width();
    int y = btpos.y() - MT_adjustedMdl->height();
    MT_adjustedMdl->move(x, y);

}


void MediaLogicBT::mdplr_lyric_show(){
    if (RT_sliderShow->currentWidget() == RT_lyricLabel)
    {
        RT_sliderShow->backview();
    }
    else
    {
        RT_sliderShow->setCurrentWidget(RT_lyricLabel);
    }
}


